/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package FrameWork.Objects.Items;

import FrameWork.GameScreen;
import FrameWork.Objects.MyObject;
import FrameWork.PSystem;
import FrameWork.RSMainGame;
import FrameWork.RSParticle;
import GamePlay.Global;
import java.io.IOException;
import java.util.Random;
import java.util.Vector;
import javax.microedition.lcdui.Graphics;
/**
 *
 * @author ASUS
 */
public class Fire extends Items{
    public PSystem m_Particle;
    protected Vector m_vItem;
    public Fire(Vector _Item,int _X,int _Y, int _SizeX, int _SizeY,
            float _TimeAni, 
            int _Map[][],int _Width, int _Height,
            int _ID) throws IOException{     
        super(_X, _Y, _SizeX, _SizeY, _TimeAni,_Map, _Width, _Height, _ID);
        m_Sprite = RSMainGame.getRS().getFire();
        m_Particle = new PSystem(RSParticle.getRS().getYellow());
        m_Particle.setOrigin(m_X*30, m_Y*30);
        m_Particle.Init();
        m_vItem = _Item;
    }
    public void Update (float _Time,int _Terrain[][]){
        super.Update(_Time,_Terrain);
        m_Particle.Update(_Time);   
        switch(m_STATUS){
            case Global.STT_INVI:
                m_TimeUpdate+=_Time;
                if(m_TimeUpdate>=0.5f){
                    m_TimeUpdate = 0;
                    m_STATUS= Global.STT_DEATH;   
                }
                break;
        }

    }
    public void UpdateAnimation (float _Time){
        m_SaveTimeAni += _Time;
        if (m_SaveTimeAni>= m_TimeAni){
            m_SaveTimeAni = 0;
            m_CurFrame= (++m_CurFrame)%7;      
        }
    }
    
     public void DrawScreen (Graphics _Graphics,
            GameScreen _Screen){
        switch(m_STATUS){
            case Global.STT_ACTIVE:
            m_Sprite.setFrame(m_CurFrame);
            m_Sprite.setPosition(m_X * 30+5 - (_Screen.getXView() - _Screen.getWidth()/2), 
                m_Y * 30-10 - (_Screen.getYView() - _Screen.getHeight()/2));
            m_Sprite.paint(_Graphics);
            
            m_Particle.DrawScreen(_Graphics, _Screen);
            break;
            case Global.STT_INVI:
                m_Particle.DrawScreen(_Graphics, _Screen);
                break;
        }
    }
    public void ActionCollision (MyObject _Object){
        if ( _Object.getSTATUS()==Global.STT_DEATH)return;
        switch (_Object.getID()){
            case Global.ID_BOOM_EXPLOSION:
                if(m_STATUS == Global.STT_ACTIVE){
                    m_STATUS = Global.STT_INVI;
                    try {
                        RandomDrodItem(m_vItem);
                    } catch (IOException ex) {
                        ex.printStackTrace();
                    } 
                }
                break;
        }
   }
   public void RandomDrodItem (Vector _Item) throws IOException{
       int t1 = m_Ran.nextInt(10);
       System.out.println("Random 0-10: "+t1);
       if(t1<3){
           Items item=null;
           Random ran = new Random();
           int t = ran.nextInt(10);
           System.out.println("Random item: "+t);
           switch(t){
               case 0:
               case 1:
                   item = new AddHeath(m_X, m_Y, m_SizeX, m_SizeY, m_TimeAni, 
                       m_Map, m_WidthMap, m_HeightMap, Global.ID_ADD_HP);
                   break;
               case 2:
                   item = new AddSpeed(m_X, m_Y, m_SizeX, m_SizeY, m_TimeAni, 
                       m_Map, m_WidthMap, m_HeightMap, Global.ID_ADD_SPEED);
                   break;
               case 3:
                   item = new AddLenBoom(m_X, m_Y, m_SizeX, m_SizeY, m_TimeAni, 
                       m_Map, m_WidthMap, m_HeightMap, Global.ID_ADD_LENGHTBOOM);
                   break;
               case 4:
                   item = new AddMaxWater(m_X, m_Y, m_SizeX, m_SizeY, m_TimeAni, 
                       m_Map, m_WidthMap, m_HeightMap, Global.ID_ADD_MAXWATER);
                   break;
               case 5:
                   item = new Kick(m_X, m_Y, m_SizeX, m_SizeY, m_TimeAni, 
                       m_Map, m_WidthMap, m_HeightMap, Global.ID_KICK);
                   break;
               case 6:
                   item = new AddBoom(m_X, m_Y, m_SizeX, m_SizeY, m_TimeAni, 
                       m_Map, m_WidthMap, m_HeightMap, Global.ID_ADD_BOOM);
                   break;
               case 7:
               case 8:
               case 9:
                   item = new Water(m_X, m_Y, m_SizeX, m_SizeY, m_TimeAni, 
                       m_Map, m_WidthMap, m_HeightMap, Global.ID_WATER);
                   break;
           }
           item.setSTATUS(Global.STT_INVI);
           _Item.addElement(item);
       }
   }
}

